#!/bin/bash

#=======================================================================
# git-wait-until-clean
# File ID: 92d46e22-d5a1-11e4-9769-000df06acc56
#
# Wait until the current Git repository is clean before continuing.
#
# Author: Øyvind A. Holm <sunny@sunbase.org>
# License: GNU General Public License version 2 or later.
#=======================================================================

unset i_str
test "$1" = "-i" && { i_str=" --ignored"; shift; }

unset u_str
test "$1" = "-u" && { u_str=" --untracked-files=no"; shift; }

unset did_wait
while test "$(git status --porcelain$i_str$u_str "$@")" != ""; do
    echo Waiting for $(hostname):$(pwd) to be cleaned up \(opt: $i_str$u_str\)... \($(date)\) >&2
    sleep 5
    did_wait=1
done
test -n "$did_wait" && echo $(hostname):$(pwd) is clean. Continuing... >&2
exit 0
